<template>
    <div>
        <!-- <div v-if="user.loadIngShow" style="width:100px;height:100px;background:red"> -->
        
        <top-menu></top-menu>
        <notification></notification>
        <!-- <transition name="fade" mode="out-in">
            <router-view></router-view>
        </transition> -->
    </div>
</template>

<script>

    import {mapState} from 'vuex';
    import Notification from './common/Notification'
    import jwtToken from './../helpers/jwt'
    import Cookie from 'js-cookie'

    import router from '../routes.js';

    import axios from 'axios'
    import Posts from './posts/Index'
    // 设置项目请求的根路径,设置以后，项目中调所有接口就会在前面拼接上根路径
    axios.defaults.baseURL = appPath+'api';
    // axios.defaults.baseURL = '/api';
    // axios.defaults.baseURL = 'http://www.c-x-y.com/api';
    // 使用axios发送post请求时,设置默认请求头中Content-Type的值
    axios.defaults.headers.post['Content-Type'] = 'application/json';
    // 给请求头加一个名为'Authorization'的参数，可以用于设置请求头带token验证
    axios.defaults.headers.common['Authorization'] = 'Bearer YWMtknehLoJT2k_f7mlPoNgo';

         axios.defaults.timeout = 10000;
        
        axios.interceptors.response.use(function (response) {
            // Do something with response data
            if(response.status==404||response.status==500){
                router.push("/error")
                // router.push({ name: 'error', params: { userId: 123 }})
            }
           /* if(response.data.length==0){
                router.push("/error")
                // router.push({ name: 'error', params: { userId: 123 }})
            } */
            return response;
        }, function (error) {
            if(error.response.status==500||error.response.status==404){
                router.push("/error")
            }
            /* if(!error.config.data){
                router.push("/error")
            }else if(error.response.status==500||error.response.status==400){
                router.push("/error")
            } */
            
            // Do something with response error
            return Promise.reject(error);
        }); 

        
    export default {
        

        created() {
            // this.$store.dispatch('refreshToken');
           /*  if (jwtToken.getToken()) { //判断是否登录
                this.$store.dispatch('setAuthUser');
            } else if(Cookie.get('auth_id')) {
                this.$store.dispatch('refreshToken');
                this.$store.dispatch('setAuthUser');
            } */
            
        },
        components:{
            TopMenu : resolve => require(["./common/TopMenu"], resolve),//首页内容
            Notification
        },
         computed:{
            ...mapState({
                user: state => state.AuthUser
            })
        },
    }
</script>
<style>
    .loading{
        width: 100%;
        text-align: center;
        background: url(../img/loading.gif) no-repeat center;
        background-size: 50%;
    }
    .contentNull{
        height: 500px;
        background: url(../img/contentNull.png) no-repeat center;
    }
    .searchClass{
        background: url(../img/searchNull.png) no-repeat center;
    }
</style>